package cn.com.fssg.platform.base.handler.impl.pjqc;

import cn.com.fssg.platform.base.handler.InterfaceHandler;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 评价期次检查是否停止录入接口
 */
@Component
public class PjqcCheckStop implements InterfaceHandler {

//    private NamedParameterJdbcTemplate jdbcTemplate = BizUtil.cur().tenantMainJdbcTemplate();

    @Autowired
    private NamedParameterJdbcTemplate jdbcTemplate;

    @Override
    public Object run(HttpServletRequest request, JSONObject jsonObject) throws Exception {
        // 评价方法（类型）
        HashMap<String, Object> params = new HashMap<>();
        String pjff = jsonObject.getString("pjff");
        // 评价年度
        String pjnd = jsonObject.getString("pjnd");
        params.put("pjff", pjff);
        params.put("pjnd", pjnd);
        String sql = "select * from bs_pjqc where pjff=:pjff and zt='停止录入' and to_char(pjkssj,'yyyy')=:pjnd";
        if (StringUtils.isNotEmpty(jsonObject.getString("pjlb"))) {
            params.put("pjlb", jsonObject.getString("pjlb"));
            sql += " and pjlb=:pjlb";
        }
        // 检查对应类型评价是否停止录入
        List<Map<String, Object>> queryForList = jdbcTemplate.queryForList(sql, params);
        return !CollectionUtils.isEmpty(queryForList);
    }

}
